package jsen.tool.ddd.handle.graph;

import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

/**
 * @author jsen
 * @date 2021/10/6
 */
@Deprecated
public class Node<D> {
    private D data;
    private final Set<Node<D>> outSet = new HashSet<>(4);
    private final Set<Node<D>> inSet = new HashSet<>(4);

    public void linkTo(Node<D> to) {
        outSet.add(to);
        to.linkFrom(this);
    }

    private void linkFrom(Node<D> from) {
        inSet.add(from);
    }

    public boolean isRoot() {
        // 入度为0
        return inSet.isEmpty();
    }

    public Set<Node<D>> getAllOutNode() {
        return outSet;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Node<?> node = (Node<?>) o;
        return Objects.equals(data, node.data);
    }

    @Override
    public int hashCode() {
        return Objects.hash(data);
    }
}
